function InfoBox(opts) {
  google.maps.OverlayView.call(this);
  this.type_ = opts.type;
  this.latlng_ = opts.latlng;
  this.map_ = opts.map;
  this.txt_ = opts.txt;
  switch(this.type_){
  case 1:
	  this.offsetVertical_ = -50;
	  this.offsetHorizontal_ = -30;
//	  this.height_ = 60;
	  this.width_ = 160;
	  break;
	case 2:
	  this.offsetVertical_ = -50;
	  this.offsetHorizontal_ = -30;
//	  this.height_ = 60;
	  this.width_ = 160;
	  break;
	case 3:
	  this.offsetVertical_ = -100;
	  this.offsetHorizontal_ = -50;
//	  this.height_ = 125;
	  this.width_ = 200;
	  break;
	case 4:
	  this.offsetVertical_ = -100;
	  this.offsetHorizontal_ = -50;
//	  this.height_ = 125;
	  this.width_ = 200;
	  break;
  }
 
  var me = this;
  this.boundsChangedListener_ =
    google.maps.event.addListener(this.map_, "bounds_changed", function() {
      return me.panMap.apply(me);
    });
  this.setMap(this.map_);
  this.setTxt = function(txt){
	  this.txt_ = txt;
  }
  this.setPos = function(latlng){
	  this.latlng_ = latlng;
  }
}
InfoBox.prototype = new google.maps.OverlayView();

InfoBox.prototype.remove = function() {
  if (this.div_) {
    this.div_.parentNode.removeChild(this.div_);
    this.div_ = null;
  }
};
InfoBox.prototype.draw = function() {
  this.createElement();
  if (!this.div_) return;
  var pixPosition = this.getProjection().fromLatLngToDivPixel(this.latlng_);
  if (!pixPosition) return;
 
  this.div_.style.width = this.width_ + "px";
  this.div_.style.left = (pixPosition.x + this.offsetHorizontal_) + "px";
  this.div_.style.height = this.height_ + "px";
  this.div_.style.top = (pixPosition.y + this.offsetVertical_) + "px";
  this.div_.style.display = 'block';
};
InfoBox.prototype.createElement = function() {
  var panes = this.getPanes();
  var div = this.div_;
  if (!div) {
    div = this.div_ = document.createElement("div");
    div.style.position = "absolute";
    div.style.background = "#fff";
	div.style.border = "1px solid #1E335F";
	div.style['border-radius'] = "5px";
//    switch(this.type_){
//	  	case 1:
//	  	    div.style.background = "#fff";
//	  	    div.style.border = "1px solid #1E335F";
//	  	    
//	  		break;
//	  	case 2:
//	  		div.style.background = "#fff";
//	  	    div.style.border = "1px solid #1E335F";
//	  		break;
//	  	case 3:
//	  		div.style.background = "#fff";
//	  	    div.style.border = "1px solid #1E335F";
//	  		break;
//	  	case 4:
//	  		div.style.background = "#fff";
//	  	    div.style.border = "1px solid #1E335F";
//	  		break;
//    }
    div.style.width = this.width_ + "px";
    div.style.height = this.height_ + "px";
    var contentDiv = document.createElement("div");
    contentDiv.style.padding = "5px 10px";
    contentDiv.innerHTML = this.txt_;
 
    div.appendChild(contentDiv);
    div.style.display = 'none';
    panes.floatPane.appendChild(div);
    this.panMap();
  } else if (div.parentNode != panes.floatPane) {
    div.parentNode.removeChild(div);
    panes.floatPane.appendChild(div);
  } else {
  }
}
 
InfoBox.prototype.panMap = function() {
  var map = this.map_;
  var bounds = map.getBounds();
  if (!bounds) return;
 
  var position = this.latlng_;
 
  var iwWidth = this.width_;
  var iwHeight = this.height_;
 
  var iwOffsetX = this.offsetHorizontal_;
  var iwOffsetY = this.offsetVertical_;
 
  var padX = 10;
  var padY = 10;
 
  var mapDiv = map.getDiv();
  var mapWidth = mapDiv.offsetWidth;
  var mapHeight = mapDiv.offsetHeight;
  var boundsSpan = bounds.toSpan();
  var longSpan = boundsSpan.lng();
  var latSpan = boundsSpan.lat();
  var degPixelX = longSpan / mapWidth;
  var degPixelY = latSpan / mapHeight;
 
  var mapWestLng = bounds.getSouthWest().lng();
  var mapEastLng = bounds.getNorthEast().lng();
  var mapNorthLat = bounds.getNorthEast().lat();
  var mapSouthLat = bounds.getSouthWest().lat();
 
  var iwWestLng = position.lng() + (iwOffsetX - padX) * degPixelX;
  var iwEastLng = position.lng() + (iwOffsetX + iwWidth + padX) * degPixelX;
  var iwNorthLat = position.lat() - (iwOffsetY - padY) * degPixelY;
  var iwSouthLat = position.lat() - (iwOffsetY + iwHeight + padY) * degPixelY;
 
  var shiftLng =
      (iwWestLng < mapWestLng ? mapWestLng - iwWestLng : 0) +
      (iwEastLng > mapEastLng ? mapEastLng - iwEastLng : 0);
  var shiftLat =
      (iwNorthLat > mapNorthLat ? mapNorthLat - iwNorthLat : 0) +
      (iwSouthLat < mapSouthLat ? mapSouthLat - iwSouthLat : 0);
 
  var center = map.getCenter();
 
  var centerX = center.lng() - shiftLng;
  var centerY = center.lat() - shiftLat;
 
  map.setCenter(new google.maps.LatLng(centerY, centerX));
 
  google.maps.event.removeListener(this.boundsChangedListener_);
  this.boundsChangedListener_ = null;
};